package com.tako;

import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;

import java.io.File;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author zhangyu
 * @date 2023/1/17
 */
public class ListItem {
    private File file;
    private final SimpleBooleanProperty check = new SimpleBooleanProperty();
    private final SimpleStringProperty src = new SimpleStringProperty();
    private final SimpleStringProperty input = new SimpleStringProperty();
    private final SimpleStringProperty output = new SimpleStringProperty();
    private final SimpleStringProperty status = new SimpleStringProperty();

    public ListItem(File file) {
        setFile(file);
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
        setCheck(true);
        setSrc(file.getName());
        File[] files = file.listFiles(f -> !f.isDirectory());
        String ipt = files == null ? "" : Stream.of(files)
                .map(File::getName)
                .collect(Collectors.joining(", "));
        String format = String.format("%d个文件：%s", files == null ? 0 : files.length, ipt);
        setInput(format);
        setOutput(file.getPath() + ".pdf");
        setStatus("");
    }

    public boolean isCheck() {
        return check.get();
    }

    public void setCheck(boolean check) {
        this.check.set(check);
    }

    public SimpleBooleanProperty checkProperty() {
        return check;
    }

    public String getSrc() {
        return src.get();
    }

    public void setSrc(String src) {
        this.src.set(src);
    }

    public SimpleStringProperty srcProperty() {
        return src;
    }

    public String getInput() {
        return input.get();
    }

    public void setInput(String input) {
        this.input.set(input);
    }

    public SimpleStringProperty inputProperty() {
        return input;
    }

    public String getOutput() {
        return output.get();
    }

    public void setOutput(String output) {
        this.output.set(output);
    }

    public SimpleStringProperty outputProperty() {
        return output;
    }

    public String getStatus() {
        return status.get();
    }

    public void setStatus(String status) {
        this.status.set(status);
    }

    public SimpleStringProperty statusProperty() {
        return status;
    }
}
